import  math
import  random
users = {"账户": [],
         "姓名": [],
         "密码": [],
         "地址": [],
         "存款余额": [],
         "开户行": [], }


def add_user():
    k = 0
    while k != 1:
        account = math.floor(1e8*random.random())
        user = users["账户"]
        for i in user:
            if i == account:
                k = 2
                break
        if len(user) >= 100:
            k = 3
            print("用户库已满!")
        if k != 2 and k != 3:
            print("您生成的账户为：", account)
            users["账户"].append(account)
            users["姓名"].append(input("姓名:"))
            users["密码"].append(int(input("密码:")))
            users["地址"].append(input("输入国家,省份,街道,门牌号:"))
            users["存款余额"].append(int(input("存款余额:")))
            users["开户行"].append("中国工商银行北京市平昌分行")
            print("注册成功!")
            k = 1
            print(users["账户"])


def save_money():    # 地址程序
    account = int(input("请输入存款账户:"))
    long = len(users["账户"])
    k = 0
    for i in users["账户"]:
        if i == account:
            moneys = users["存款余额"][k]
            moneys_1 = moneys
            money = int(input("请输入存款金额:"))
            users["存款余额"][k] = money + moneys_1
            print(users["存款余额"])
            return True
        k += 1
    if k == long:
        return False


def graw_money():     # 银行程序
    account = int(input("输入取款账户:"))
    code = int(input("输入密码:"))
    money = int(input("输入取款金额:"))
    k = 0
    g = 0
    ll = 0
    for i in users["账户"]:
        if i == account:
            g = 1
            break
        k += 1
    if g == 1:
        code_1 = users["密码"][k]
        if code == code_1:
            ll = 1
    else:
        print("账户不存在!")
    if g == 1 and ll == 1:
        moneys = users["存款余额"][k]
        if moneys >= money:
            users["存款余额"][k] = moneys - money
        else:
            print("钱不够")


def transfer_accounts():    # 界面程序
    account_1 = int(input("输入转出账户:"))
    account_2 = int(input("输入转入账户:"))
    code = int(input("输入转出账户密码:"))
    money = int(input("输入转出金额:"))
    k = 0
    kk = 0
    g = 0
    gg = 0
    ll = 0
    for i in users["账户"]:
        if i == account_1:
            g = 1
            break
        k += 1
    for i in users["账户"]:
        if i == account_2:
            gg = 1
            break
        kk += 1
    if g == 1 and gg == 1:
        code_1 = users["密码"][k]
        if code == code_1:
            ll = 1
        else:
            print("密码不对！")
    else:
        print("账户不对!")
    if g == 1 and ll == 1 and gg == 1:
        moneys = users["存款余额"][k]
        moneys_1 = users["存款余额"][kk]
        if moneys >= money:
            users["存款余额"][k] = moneys - money
            users["存款余额"][kk] = moneys_1 + money
        else:
            print("钱不够")


def check_account():
    account = int(input("输入查询账户:"))
    code = int(input("输入密码:"))
    k = 0
    g = 0
    for i in users["账户"]:
        if i == account:
            g = 1
            break
        k += 1
    if g == 1:
        code_1 = users["密码"][k]
        if code == code_1:
            print(f"当前账户为：{users['账户'][k]}")
            print(f"当前密码为：{users['密码'][k]}")
            print(f"当前余额为：{users['存款余额'][k]}")
            print(f"当前地址为：{users['地址'][k]}")
            print(f"当前开户行为：{users['开户行'][k]}")
        else:
            print("密码错误!")
    else:
        print("该用户不存在!")


def interface():
    while True:
        print("******************************")
        print("*         中国工商银行          *")
        print("*         账户管理系统          *")
        print("*             V1.0            *")
        print("******************************")
        print("")
        print("*1.开户                        *")
        print("*2.存钱                        *")
        print("*3.取钱                        *")
        print("*4.转账                        *")
        print("*5.查询                        *")
        print("*6.Bye!                       *")
        print("******************************")
        exchange = int(input())
        if exchange == 1:
            add_user()
        elif exchange == 2:
            save_money()
        elif exchange == 3:
            graw_money()
        elif exchange == 4:
            transfer_accounts()
        elif exchange == 5:
            check_account()
        elif exchange == 6:
            break


if __name__ == '__main__':
    interface()
